package com.example.ad_project;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.nus.iss.ad.model.OrderDetail;

public class OrderDetailAdapter extends ArrayAdapter<OrderDetail> 
{
    private Context context;
	private OrderDetail[] values;

	public  OrderDetailAdapter(Context context, OrderDetail[] values) {
	   super(context, R.layout.confirm_detail_row, values);
	   this.context = context;
	   this.values = values;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        View v=convertView;
        if (convertView == null) {
        	LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            v = inflater.inflate(R.layout.confirm_detail_row, null);
        }
        TextView tCode = (TextView)v.findViewById(R.id.textViewCode);
        TextView tName = (TextView)v.findViewById(R.id.textViewName);
        TextView tQty = (TextView)v.findViewById(R.id.textViewQty);
        CheckBox c1=(CheckBox)v.findViewById(R.id.checkBox1);
        
        OrderDetail od=values[position];
        String code=od.getInventoryId();
        String name=od.getInventory().getDescription();
        String qty=Integer.toString(od.getQuantity());
        tCode.setText(code);
        tName.setText(name);
        tQty.setText(qty);
        
        c1.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)context);
       
        return v;
		
	}
}